package com.itcast.plane.modoule.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itcast.plane.common.ConsHint;
import com.itcast.plane.modoule.admin.domain.Admin;
import com.itcast.plane.modoule.admin.dto.AdminLogDTO;
import com.itcast.plane.modoule.admin.mapper.AdminMapper;
import com.itcast.plane.util.JsonResult;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

@Service
public class AdminService extends ServiceImpl<AdminMapper, Admin> {

    @Resource
    private AdminMapper adminMapper;

    public JsonResult login(AdminLogDTO logDTO) {
        LambdaQueryWrapper<Admin> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        Admin admin = adminMapper.selectOne(lambdaQueryWrapper.eq(Admin::getAccount,logDTO.getAccount()));
        if (ObjectUtils.isEmpty(admin)){
            return new JsonResult(false, ConsHint.LOGIN_DEFAULT);
        }else if (admin.getPassword().equals(logDTO.getPassword())){
            return new JsonResult(true,ConsHint.LOGIN_SUCCESSFULLY,admin);
        }else {
            return new JsonResult(false,ConsHint.LOGIN_DEFAULT);
        }
    }
}
